package com.jnu.hospitalexamination.mapper;

import com.jnu.hospitalexamination.entity.Cireport;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jnu.hospitalexamination.entity.vo.CireportVO;
import com.jnu.hospitalexamination.entity.vo.ReportitemVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author Nowonder
* @description 针对表【cireport】的数据库操作Mapper
* @createDate 2024-07-21 20:13:39
* @Entity .entity.Cireport
*/
@Mapper
public interface CireportMapper extends BaseMapper<Cireport> {
    /**
     * 根据用户id获取报告列表
     * @param userId 医院ID
     * @return 当天预约人数
     */
    @Select("SELECT h.name AS hospitalname, o.orderDate, o.orderId\n" +
            "FROM cireport cr\n" +
            "JOIN orders o ON o.orderId = cr.orderId\n" +
            "JOIN hospital h ON o.hpId = h.hpId\n" +
            "WHERE o.userId = #{userId}\n" +
            "GROUP BY h.name, o.orderDate, o.orderId\n" +
            "ORDER BY o.orderDate;")
    public List<ReportitemVO> selectbyuserid(@Param("userId") Integer userId);

    /**
     * 根据订单id获取报告
     * @param orderId
     * @return
     */
    @Select("SELECT * FROM cireport WHERE orderId = #{orderId}")
    List<CireportVO> SelectByOrderId(int orderId);
}




